package com.example.zhuyu.login.module.mvp.presenter;

import com.example.zhuyu.basemvp.base.BasePresenter;
import com.example.zhuyu.basemvp.di.scope.ActivityScope;
import com.example.zhuyu.basemvp.http.BaseObserver;
import com.example.zhuyu.basemvp.http.BaseResponse;
import com.example.zhuyu.basemvp.utils.RxLifecycleUtil;
import com.example.zhuyu.login.module.mvp.contract.LoginContract;
import com.example.zhuyu.login.module.mvp.entity.response.LoginResponse;

import java.util.HashMap;
import java.util.Map;

import javax.inject.Inject;

/**
 * @author zhuyu
 * @date 2019/2/20
 * @desc
 */

@ActivityScope
public class LoginPresenter extends BasePresenter<LoginContract.View,LoginContract.Model> {

    /**
     * 将LoginModule中已经提供的view和model注入到此方法中
     * @param view view
     * @param model model
     */
    @Inject
    public LoginPresenter(LoginContract.View view, LoginContract.Model model) {
        //此时调用父类BasePresenter的构造方法将view和model对protect的变量（mView,mModel）进行赋值,
        // 以便BasePresenter的子类可以方便的调用
        super(view, model);
    }

    public void requestNet(){

        Map<String,String> map = new HashMap<>();
        map.put("phone","13594347817");
        map.put("passwd","123456");
        map.put("key","00d91e8e0cca2b76f515926a36db68f5");
        mModel.login(map)
                .compose(RxLifecycleUtil.<BaseResponse<LoginResponse>>bindUntilEvent(mView))
                .subscribe(new BaseObserver<BaseResponse<LoginResponse>>(mView) {
                    @Override
                    public void onHandleSuccess(BaseResponse<LoginResponse> loginResponseBaseResponse) {

                        mView.showSuccessData(loginResponseBaseResponse.getData().toString());
                    }

                    @Override
                    public void onHandleFail(BaseResponse<LoginResponse> loginResponseBaseResponse) {

                    }
                });


    }


}
